home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_533 / convert / convert.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  134 lines

  1. /*****************************************
  2.  ***
  3.  *** FILE   : Convert.c
  4.  *** ------------------------------------
  5.  *** DATE   : 10.07.91
  6.  *** ------------------------------------
  7.  *** AUTHOR : Frank Enderle
  8.  *** ------------------------------------
  9.  *** VERSION: 1.1
  10.  ***
  11.  *****************************************/
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <stdio.h>
  16. #include <libraries/dosextens.h>
  17.  
  18. struct FileLock *MyLock;
  19. struct FileInfoBlock *MyFIB;
  20. struct FileHandle *MyHandle;
  21.  
  22. UBYTE *Buffer;
  23. BYTE  CSI[1] = {0x9B};
  24. UBYTE SrcFile[80],DstFile[80],ModName[80],Name[80];
  25. BYTE  Ans[5];
  26. BOOL  OK;
  27. int   i,Length;
  28. FILE  *Handle;
  29.  
  30. main()
  31. {
  32.  printf("\f\n");
  33.  printf("Object to C V1.1\n");
  34.  printf("----------------\n\n");
  35.  
  36.  printf("(c) 1991 Frank Enderle\n\n");
  37.  
  38.  printf("\n");
  39.  printf("Sourcefile      (RAW-DATA)   : ");
  40.  scanf("%s",SrcFile);
  41.  printf("Destinationfile (D  -DATA)   : ");
  42.  scanf("%s",DstFile);
  43.  printf("Module Name                  : ");
  44.  scanf("%s",ModName);
  45.  
  46.  MyFIB  = AllocMem(sizeof(struct FileInfoBlock),MEMF_CHIP|MEMF_CLEAR);
  47.  if(MyFIB  == NULL) CloseAll("*** No Mem for FileInfoBlock");
  48.  
  49.  MyLock = Lock(SrcFile,ACCESS_READ);
  50.  if(MyLock == NULL) CloseAll("*** Sourcefile not found");
  51.  
  52.  OK     = Examine(MyLock,MyFIB);
  53.  if(OK     == NULL) CloseAll("*** Can't examine FileInfoBlock");
  54.  
  55.  UnLock(MyLock);
  56.  MyLock = NULL;
  57.  
  58.  if(MyFIB->fib_DirEntryType > NULL) CloseAll("*** File is a Directory");
  59.  printf("\n");
  60.  printf("Filelength                   : %6d ( $%08x ) \n",MyFIB->fib_Size,MyFIB->fib_Size);
  61.  printf("Used Blocks                  : %6d ( $%08x ) \n",MyFIB->fib_NumBlocks,MyFIB->fib_NumBlocks);
  62.  printf("\n");
  63.  printf("Length                       : %6d ( $%08x ) \n",MyFIB->fib_Size,MyFIB->fib_Size);
  64.  printf("Actual Position              : ");
  65.  
  66.  Buffer = AllocMem(MyFIB->fib_Size,MEMF_PUBLIC|MEMF_CLEAR);
  67.  
  68.  MyHandle = Open(SrcFile,MODE_OLDFILE);
  69.  if(MyHandle == NULL) CloseAll("*** Error while reading");
  70.  Read(MyHandle,Buffer,MyFIB->fib_Size);
  71.  Close(MyHandle);
  72.  MyHandle = NULL;
  73.  
  74.  Length = 0;
  75.  sprintf(Name,"%s.c",DstFile);
  76.  
  77.  Handle = fopen(Name,"w");
  78.  if(Handle == NULL) CloseAll("*** Error while writing");
  79.  
  80.  fprintf(Handle,"/*\n");
  81.  fprintf(Handle," * Module : %s\n",ModName);
  82.  fprintf(Handle," * File   : %s\n",SrcFile);
  83.  fprintf(Handle," *\n");
  84.  fprintf(Handle," * Created with Object to C by F.Enderle\n");
  85.  fprintf(Handle,"*/\n\n");
  86.  fprintf(Handle,"#include <exec/types.h>\n\n");
  87.  fprintf(Handle,"BYTE %s[%d] = {\n\n",ModName,MyFIB->fib_Size);
  88.  
  89.  for(i=0;i<MyFIB->fib_Size;i++)
  90.  {
  91.   printf("%s16;32H%6d ( $%08x )",CSI,i,i);
  92.   if(Length==0) fprintf(Handle,"   ");
  93.   fprintf(Handle,"0x%02x",Buffer[i]);
  94.   Length++;
  95.   if(Length<12)
  96.    if(i<MyFIB->fib_Size-1) fprintf(Handle,", ");
  97.   if(Length>=12)
  98.   {
  99.    fprintf(Handle,",\n");
  100.    Length = 0;
  101.   }
  102.  }
  103.  printf("%s16;32H%6d ( $%08x )",CSI,i,i);
  104.  fprintf(Handle,"\n\n};\n");
  105.  fclose(Handle);
  106.  Handle = NULL;
  107.  
  108.  CloseAll("Operation successful");
  109. }
  110.  
  111. CloseAll(ErrMsg)
  112. UBYTE ErrMsg[80];
  113. {
  114.  printf("\n\n%s\n",ErrMsg);
  115.  if (MyHandle != NULL) Close(MyHandle);
  116.  if (MyLock != NULL  ) UnLock(MyLock);
  117.  if (MyFIB  != NULL  ) FreeMem(MyFIB,sizeof(struct FileInfoBlock));
  118.  if (Buffer != NULL  ) FreeMem(Buffer,MyFIB->fib_Size);
  119.  if (Handle != NULL  ) fclose(Handle);
  120.  exit(NULL);
  121. }
  122.  
  123.  
  124. _abort()
  125. {
  126.  CloseAll("*** ABORTED BY USER");
  127.  exit(NULL);
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.